#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/6/27 15:32
# @Author : cjw

from web_wework.page.base_page import BasePage
from web_wework.setting import ELEMENT_YML
from web_wework.util.file_operator import YmlOperator


class AddMemberPage(BasePage):
    """添加成员页面"""
    # 添加定位元素到locators
    BasePage.locators.update(YmlOperator(ELEMENT_YML['amp']).data)

    def add_member(self, username, acct_id, phone, mail):
        """
        添加成员
        :param username: 姓名
        :param acct_id: 账号
        :param phone: 手机号
        :param mail: 邮箱
        :return:
        """
        from web_wework.page.contact_page import ContactPage

        self._add_member(username, acct_id, phone, mail)
        return ContactPage(self.driver)

    def add_member_fail(self, username, acct_id, phone, mail, tips_loc):
        """
        添加成员失败
        :param username: 姓名
        :param acct_id: 账号
        :param phone: 手机号
        :param mail: 邮箱
        :param tips_loc: 错误信息定位名称
        :return:
        """
        self._add_member(username, acct_id, phone, mail)
        return self.find(self.locators[tips_loc]).text

    def _add_member(self, username, acct_id, phone, mail):
        """输入添加成员信息"""
        self.username.send_keys(username)
        self.acctid.send_keys(acct_id)
        self.phone.send_keys(phone)
        self.mail.send_keys(mail)
        self.save.click()
